<!--  slider 滑块 - 属性面板 -->
<template>
  <div class="sliderAttr">
    <div class="content">
      <div class="title">
        {{ attributeset.lab }}
      </div>
      <div v-if="attributeset.data" class="list">
        <div class="lab">字段标题：<span>最多30个字</span></div>
        <div>
          <t-input
            v-model="attributeset.data.title"
            type="text"
            size="small"
            :maxlength="30"
            placeholder="请输入"
          />
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">最大值：</div>
          <div>
            <t-input-number
              v-model="attributeset.data.maxValue"
              size="small"
              :min="attributeset.data.minValue"
              :max="100"
              placeholder="请输入最大值"
            />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">最小值：</div>
          <div>
            <t-input-number
              v-model="attributeset.data.minValue"
              size="small"
              placeholder="请输入最小值"
              :min="0"
              :max="attributeset.data.maxValue"
            />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">步长：</div>
          <div>
            <t-input-number
              v-model="attributeset.data.step"
              size="small"
              placeholder="请输入最小值"
            />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">默认值：</div>
          <div>
            <t-input-number
              v-model="attributeset.data.defaultValue"
              size="small"
              placeholder="请输入最小值"
              :min="attributeset.data.minValue"
              :max="attributeset.data.maxValue"
            />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">表单宽度：</div>
          <div class="slider">
            <t-slider v-model="attributeset.data.width" size="small" />
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">表单列数</div>
          <div>
            <t-radio-group
              v-model="attributeset.data.defaultWidth"
              default-value="1"
              size="small"
              @change="widthChange"
            >
              <t-radio-button value="1">一列</t-radio-button>
              <t-radio-button value="2">两列</t-radio-button>
              <t-radio-button value="3">三列</t-radio-button>
              <t-radio-button value="4">四列</t-radio-button>
            </t-radio-group>
          </div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">是否只读</div>
          <div><t-switch v-model="attributeset.data.isReadOnly" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">显示标题</div>
          <div><t-switch v-model="attributeset.data.isShowTitle" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">隐藏组件</div>
          <div><t-switch v-model="attributeset.data.isShow" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">是否必填</div>
          <div><t-switch v-model="attributeset.data.isMust" /></div>
        </div>
        <div class="fx-sb fx-al-ct">
          <div class="lab">数值显示</div>
          <div><t-switch v-model="attributeset.data.numShow" /></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { reactive, watch } from 'vue'

const props = defineProps({
  arrtData: Object
})

let attributeset = reactive({ ...props.arrtData })
// 处理列的调整宽度
const widthChange = (val) => {
  switch (val) {
    case '1':
      attributeset.data.width = 100
      break
    case '2':
      attributeset.data.width = 50
      break
    case '3':
      attributeset.data.width = 33.3
      break
    case '4':
      attributeset.data.width = 25
      break
  }
}

// 接收父级的方法
const emit: Function = defineEmits(['changeAttrHandle'])
// 同步调整attributeset
watch(
  () => props.arrtData,
  (val) => {
    attributeset = { ...val }
  },
  { deep: true }
)
// 监听整个表单的输入
watch(
  () => attributeset,
  (val) => {
    emit('changeAttrHandle', val)
  },
  { deep: true }
)
</script>
<style src="../../index.less" scoped></style>
